﻿' ----------------------------------------------------------------------------------
' Microsoft Developer & Platform Evangelism
' 
' Copyright (c) Microsoft Corporation. All rights reserved.
' 
' THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES 
' OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ----------------------------------------------------------------------------------
' The example companies, organizations, products, domain names,
' e-mail addresses, logos, people, places, and events depicted
' herein are fictitious.  No association with any real company,
' organization, product, domain name, email address, logo, person,
' places, or events is intended or should be inferred.
' ----------------------------------------------------------------------------------

Imports Microsoft.Samples.WindowsPhoneCloud.Phone.ViewModel

Namespace PivotContent

    Partial Public Class NotificationsPage
        Inherits UserControl
        Public Sub New()
            Me.InitializeComponent()
        End Sub

        Public Custom Event BeginPushConnection As EventHandler(Of EventArgs)
            AddHandler(ByVal value As EventHandler(Of EventArgs))
                AddHandler Me.ViewModel.BeginPushConnection, value
            End AddHandler
            RemoveHandler(ByVal value As EventHandler(Of EventArgs))
                RemoveHandler Me.ViewModel.BeginPushConnection, value
            End RemoveHandler
            RaiseEvent(ByVal sender As System.Object, ByVal e As EventArgs)
            End RaiseEvent
        End Event

        Public Custom Event EndPushConnection As EventHandler(Of EventArgs)
            AddHandler(ByVal value As EventHandler(Of EventArgs))
                AddHandler Me.ViewModel.EndPushConnection, value
            End AddHandler
            RemoveHandler(ByVal value As EventHandler(Of EventArgs))
                RemoveHandler Me.ViewModel.EndPushConnection, value
            End RemoveHandler
            RaiseEvent(ByVal sender As System.Object, ByVal e As EventArgs)
            End RaiseEvent
        End Event

        Public Property ViewModel() As NotificationsPageViewModel
            Get
                Return TryCast(Me.DataContext, NotificationsPageViewModel)
            End Get
            Set(ByVal value As NotificationsPageViewModel)
                Me.DataContext = value
            End Set
        End Property

        Private Sub OnNotificationsPageLoaded(ByVal sender As Object, ByVal args As RoutedEventArgs) Handles Me.Loaded
            If Me.ViewModel IsNot Nothing Then
                Me.ViewModel.CleanPushNotificationServiceException()

                AddHandler Me.ViewModel.PushNotificationServiceException, AddressOf Me.ViewModel.ShowError

                If Me.ViewModel.IsPushEnabled Then
                    Me.ViewModel.ConnectToPushNotificationService()
                End If
            End If
        End Sub
    End Class
End Namespace